package com.kevin.common;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.nutz.dao.Cnd;
import org.nutz.dao.util.cri.SqlExpressionGroup;

import com.kevin.util.DateConvertUtil;

public class RequestParamUtil {
	public static SqlExpressionGroup dealRequest(HttpServletRequest req){
		SqlExpressionGroup group = Cnd.exps("1", "=", "1");
		Enumeration<String> attrs =  req.getParameterNames();
		while (attrs.hasMoreElements()) {
			String paramName = (String) attrs.nextElement();
			String paramValue = req.getParameter(paramName);
			System.out.println(" "+paramName);
			
			if(paramValue != null && !paramValue.equals("")){
				if(paramName.startsWith("exact_")){//精确查询
					String[] attrNames = paramName.split("exact_");
					group = group.and(attrNames[1], "=", paramValue);
				}else if(paramName.startsWith("fuzzy_")){//模糊查询
					String[] attrNames = paramName.split("fuzzy_");
					group = group.and(attrNames[1], "like", paramValue);
				}else if(paramName.startsWith("date_")){//日期查询
					if(paramName.startsWith("date_s")){//日期大于
						String[] attrNames = paramName.split("date_s");
						group = group.and(attrNames[1], ">", DateConvertUtil.convertDate(paramValue,"yyyy-MM-dd"));
					}
					if(paramName.startsWith("date_e")){//日期小于
						String[] attrNames = paramName.split("date_e");
						group = group.and(attrNames[1], "<", DateConvertUtil.convertDate(paramValue,"yyyy-MM-dd"));
					}
				}else {
					
				}				
			}
		}
		return group;
	}

}
